package com.jk.controller;

import com.jk.annotation.MyLog;
import com.jk.dto.TemUser;
import com.jk.pojo.PagedResponse;
import com.jk.pojo.ResponseResult;
import com.jk.service.TemUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yzf
 * @version 1.0
 * @ClassName TemUserController
 * @program: yzf-test
 * @description: TODO
 * @date 2025/2/27 19:49
 */
@Slf4j
@Api(tags = "用户管理")
@RestController
@RequestMapping("/temUser")
public class TemUserController {
    @Autowired
    private TemUserService temUserService;
    @Autowired
    private MongoTemplate mongoTemplate;

    @ApiOperation(value = "查询用户信息",httpMethod = "POST",notes = "查询用户信息")
    @MyLog(url = "/temUser/findUserList")
    @PostMapping("/findUserList")
//    @PreAuthorize("hasAnyAuthority('system:student:list')")    //自带的权限管理注解
    @PreAuthorize("@pms.hasPermission('system:student:list')")    //自定义权限管理
    public List<TemUser> findUserList(@RequestBody TemUser temUser){
//        mongoTemplate.save(temUser);
        return temUserService.findUserList(temUser);
    }
    @ApiOperation(value = "新增用户信息",httpMethod = "POST",notes = "新增用户信息")
    @PostMapping("/addUser")
    @MyLog(url = "/temUser/addUser")
    public void addUser(@RequestBody TemUser temUser){

        temUserService.addUser(temUser);
    }

    @ApiOperation(value = "分页查询",httpMethod = "POST",notes = "分页查询")
    @PostMapping("/findUserListByPage")
    public ResponseResult<PagedResponse<TemUser>> findUserListByPage(@RequestBody TemUser temUser,@RequestParam(value = "pageNum") Integer pageNum,@RequestParam(value = "pageSize") Integer pageSize){

       return new ResponseResult<>(200,"查询成功", temUserService.findUserListByPage(temUser, pageNum, pageSize));
    }






}
